<template>
    <div :class="{'ly-is-full':isFull}">
        <div class="tableSelect" ref="tableSelect">
            <el-form :inline="true" :model="formInline" label-position="left">
                <el-form-item label="建筑名称：">
                    <el-input v-model.trim="formInline.order_id" maxlength="60"  clearable placeholder="建筑名" @change="search" style="width:200px"></el-input>
                </el-form-item>
                <el-form-item label=""><el-button  @click="search" type="primary" icon="Search">查询</el-button></el-form-item>
                <el-form-item label=""><el-button  @click="handleEdit('','reset')" icon="Refresh">重置</el-button></el-form-item>
                <el-form-item label=""><el-button  @click="addModule" type="primary">新增</el-button></el-form-item>
                <el-form-item label=""><el-button  @click="handleDelete" type="danger" :disabled="multiple">删除</el-button></el-form-item>
            </el-form>
        </div>
        <div class="table">
            <el-table :height="tableHeight" :border="true" :data="tableData" v-loading="loadingPage" ref="tableref" style="width: 100%" @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="60" align="center"></el-table-column>
                <el-table-column prop="sn" width="120" align="center" label="编号"></el-table-column>
                <el-table-column prop="house_name" label="建筑名称" width="200" show-overflow-tooltip></el-table-column>
                <el-table-column prop="house_type" label="建筑类型" width="180"></el-table-column>
                <el-table-column prop="address" label="地址" width="250"></el-table-column>
                <el-table-column prop="level" label="潜力等级" width="120"></el-table-column>
                <el-table-column prop="house_lng" label="经度" width="120"></el-table-column>
                <el-table-column prop="house_lat" label="维度" width="120"></el-table-column>
                <el-table-column width="200" prop="create_datetime" label="创建时间"></el-table-column>
                <el-table-column label="操作" fixed="right" width="150">
                    <template #header>
                        <div style="display: flex;justify-content: space-between;align-items: center;">
                            <div>操作</div>
                            <div @click="setFull">
                                <el-tooltip content="全屏" placement="bottom">
                                    <el-icon ><full-screen /></el-icon>
                                </el-tooltip>
                            </div>
                        </div>
                    </template>
                    <template #default="scope">
                        <span class="table-operate-btn" @click="handleEdit(scope.row,'import')">匹配</span>
                        <span class="table-operate-btn" @click="handleEdit(scope.row,'edit')">编辑</span>
                        <span class="table-operate-btn" @click="handleEdit(scope.row,'delete')">删除</span>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
        <add-module-goods-manage ref="addModuleFlag" @refreshData="getData"></add-module-goods-manage>
        <import-module-manage ref="importModuleFlag" @refreshData="getData"></import-module-manage>

    </div>
</template>
<script>
    import Pagination from "@/components/Pagination";
    import {mallGoodsbrand,mallGoodsbrandDelete} from '@/api/api'
    import AddModuleGoodsManage from "./components/addModuleGoodsBrand";
    import ImportModuleManage from "./components/analysis";
    import { lyMixins } from "@/mixins/mixins"
    export default {
        mixins: [lyMixins],
        components:{
            AddModuleGoodsManage,
            ImportModuleManage,
            Pagination,
        },
        name:'goodsManage',
        data() {
            return {
                isFull:false,
                loadingPage:false,
                // 选项框选中数组
                ids: [],
                // 选项框非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                formInline:{
                    page: 1,
                    limit: 10,
                },
                pageparm: {
                    page: 1,
                    limit: 10,
                    total: 0
                },
                statusList:[
                    {id:0,name:'排队中'},
                    {id:2,name:'正在导出'},
                    {id:1,name:'导出成功'},
                    {id:3,name:'导出失败'},
                ],
                timers:[],
                tableData:[],
                categoryList:[]
            }
        },
        methods:{
            setFull(){
                this.isFull=!this.isFull
                window.dispatchEvent(new Event('resize'))
            },
            //多选项框被选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.id);
                this.single = selection.length !== 1;
                this.multiple = !selection.length;
            },
            /** 批量删除按钮操作 */
            handleDelete(row) {
                const ids = this.ids;
                let vm = this
                vm.$confirm('是否确认删除选中的数据项?', "警告", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(function() {
                    return mallGoodsbrandDelete({id:ids}).then(res=>{
                        if(res.code == 2000) {
                            vm.$message.success(res.msg)
                            vm.search()
                        } else {
                            vm.$message.warning(res.msg)
                        }
                    })
                })
            },
            addModule() {
                this.$refs.addModuleFlag.addModuleFn(null,'新增',this.categoryList)
            },
            handleEdit(row,flag) {
                if(flag=='edit') {
                    this.$refs.addModuleFlag.addModuleFn(row,'编辑',this.categoryList)
                } else if(flag=='price') {
                    this.$router.push({name:'priceManage',query:{id:row.id,name:row.name}})
                } else if(flag=='down') {
                    mallPojectDown(row.id).then(blob=>{
                        let fileName = row.name + '.xlsx'
                        if (window.navigator.msSaveOrOpenBlob) {
                            navigator.msSaveBlob(blob, fileName)
                        } else {
                            var link = document.createElement('a')
                            link.href = window.URL.createObjectURL(blob)
                            link.download = fileName
                            link.click()
                            window.URL.revokeObjectURL(link.href)
                        }
                        
                        
                    })
                } else if(flag=='delete') {
                    let vm = this
                    vm.$confirm('您确定要删除选中的数据吗？',{
                        closeOnClickModal:false
                    }).then(res=>{
                        mallGoodsbrandDelete({id:row.id}).then(res=>{
                            if(res.code == 2000) {
                                vm.$message.success(res.msg)
                                vm.search()
                            } else {
                                vm.$message.warning(res.msg)
                            }
                        })
                    }).catch(()=>{

                    })
                } else if(flag=="reset"){
                    this.formInline = {
                        page:1,
                        limit: 10
                    }
                    this.pageparm={
                        page: 1,
                        limit: 10,
                        total: 0
                    }
                    this.getData()
                } else if(flag=="Passed"){
                    this.$router.push({name:'priceManage',query:{id:row.id,name:row.name}})
                    this.$router.push({name:'cadManage',query:{id:row.id,name:row.name}})
                } else if(flag=="import"){
                    this.$refs.importModuleFlag.addModuleFn(row,'导入aa00',this.categoryList)
                }
            },
            callFather(parm) {
                this.formInline.page = parm.page
                this.formInline.limit = parm.limit
                this.getData()
            },
            search() {
                this.formInline.page = 1
                this.formInline.limit = 10
                this.getData()
            },
            //获取列表
            async getData() {
                this.loadingPage = true
                mallGoodsbrand(this.formInline).then(res => {
                     this.loadingPage = false
                     if(res.code ==2000) {
                         this.tableData = res.data.data
                         this.pageparm.page = res.data.page;
                         this.pageparm.limit = res.data.limit;
                         this.pageparm.total = res.data.total;
                     }
                 })
            }
        },
        created() {
            this.getData()
        },
    }
</script>

